home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS1.ZIP
/
MAIL
/
ALIAS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-20
|
17KB
|
446 lines
/*--------------------------------------------------------------------*/
/* a l i a s . c */
/* */
/* Smart routing and alias routines for UUPC/extend mail */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/* */
/* Additional code */
/* Copyright (c) Richard H. Lamb 1985, 1986, 1987 */
/* Changes Copyright (c) Stuart Lynne 1987 */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: alias.c 1.6 1993/07/21 01:19:16 ahd Exp $
*
* Revision history:
* $Log: alias.c $
* Revision 1.6 1993/07/21 01:19:16 ahd
* Incr elements after filling info from passwd, not before!
*
* Revision 1.5 1993/07/19 02:52:11 ahd
* Don't load alias for empty names
*
* Revision 1.4 1993/05/06 03:41:48 ahd
* Use expand_path to get reasonable correct drive for aliases file
*
* Revision 1.3 1993/04/11 00:33:05 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.2 1992/11/22 21:06:14 ahd
* Use strpool for memory allocation
*
* 02 Oct 89 Alter large strings/structures to use
* malloc()/free() ahd
* 08 Feb 90 Correct failure of ExtractAddress to return
* non-names ahd
* 18 Mar 90 Move checkname() and associated routines into
* hostable.c ahd
* 22 Apr 90 Modify user_at_node to correctly handle .UUCP
* alias on local host. ahd
*
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#ifndef __TURBOC__
#include <search.h>
#endif
#include "lib.h"
#include "hostable.h"
#include "security.h"
#include "usertabl.h"
#include "hlib.h"
#include "alias.h"
#include "address.h"
#include "expath.h"
static size_t AliasCount = 0;
static struct AliasTable *alias = NULL;
int nickcmp( const void *a, const void *b );
static size_t LoadAliases( void ) ;
currentfile();
/*--------------------------------------------------------------------*/
/* I n i t R o u t e r */
/* */
/* Verify, initialize the global routing data */
/*--------------------------------------------------------------------*/
boolean InitRouter()
{
boolean success = TRUE; /* Assume the input data is good */
struct HostTable *Hptr;
/*--------------------------------------------------------------------*/
/* Verify that the user gave us a good name server */
/*--------------------------------------------------------------------*/
Hptr = checkreal(E_mailserv);
if (Hptr == BADHOST)
{
printmsg(0,"mail server '%s' must be listed in SYSTEMS file",
E_mailserv);
success = FALSE;
}
else if (Hptr->hstatus == localhost) /* local system? */
{
printmsg(0,"'%s' is name of this host and cannot be mail server",
E_mailserv);
success = FALSE;
}
/*--------------------------------------------------------------------*/
/* Return to caller */
/*--------------------------------------------------------------------*/
return success;
} /* InitRouter */
/*--------------------------------------------------------------------*/
/* E x t r a c t N a m e */
/* */
/* Returns full name of user, and returns address if name */
/* is not available. */
/*--------------------------------------------------------------------*/
void ExtractName(char *result, char *column)
{
static int recursion = 0;
recursion++;
printmsg((recursion > 2) ? 1:8,
"ExtractName: Getting name from '%s'",column);
ExtractAddress(result, column, TRUE); /* Get the full name */
if (!strlen(result)) /* Did we get the name? */
{ /* No --> Get the e-mail address */
char addr[MAXADDR];
char path[MAXADDR];
char node[MAXADDR];
char *fullname;
ExtractAddress(addr,column, FALSE);
user_at_node(addr,path,node,result);
/* Reduce address to basics */
fullname = AliasByAddr(node,result);
if (fullname == NULL)
{
strcat(result,"@");
strcat(result,node);
}
else
strcpy(result,fullname);
}
printmsg((recursion > 2) ? 1: 8,"ExtractName: name is '%s'",result);
recursion--;
return;
} /*ExtractName*/
/*--------------------------------------------------------------------*/
/* B u i l d A d d r e s s */
/* */
/* Builds a standard address format, with aliasing as */
/* required. */
/*--------------------------------------------------------------------*/
void BuildAddress(char *result, const char *input)
{
char addr[MAXADDR];
char name[MAXADDR];
char user[MAXADDR];
char path[MAXADDR];
char node[MAXADDR];
char *fulladdr;
/*--------------------------------------------------------------------*/
/* It must be a real address, possibly with a name attached; get */
/* the address portion, break the address into user and node, and */
/* then see if we know the person by address */
/*--------------------------------------------------------------------*/
ExtractAddress(addr,input,FALSE); /* Get user e-mail addr */
user_at_node(addr,path,node,user); /* Break address down */
fulladdr = AliasByAddr(node,user); /* Alias for the address? */
if (fulladdr != NULL) /* Yes --> Use it */
{
strcpy(result,fulladdr);
return;
} /* if */
/*--------------------------------------------------------------------*/
/* We don't know the address yet; get the name the user provided, */
/* and then normalize the address */
/*--------------------------------------------------------------------*/
ExtractAddress(name,input,TRUE); /* Also get their name */
if (strlen(name)) /* Did we find a name for user? */
{ /* Yes --> Return it */
char *s = strchr(node, '.');
if ((s == NULL) || equalni( s, ".UUCP", 5))
/* Simple name or UUCP domain? */
{ /* Yes--> Use original address */
size_t pathlen = strlen(path);/* Save len of orig path */
if ((p